package cn.gene.timeyan.article.webapi.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import cn.gene.timeyan.article.service.CommentService;
import cn.gene.timeyan.common.restful.JsonResult;
import cn.gene.timeyan.pojo.article.dto.CommentDTO;
import cn.gene.timeyan.pojo.article.vo.CommentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 鏂囩珷璇勮?淇℃伅 前端控制器
 * </p>
 *
 * @author LWG
 * @since 2022-07-25
 */
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;
    private static final int PAGESIZE=10;

    @PostMapping("/add")
    @ApiOperation("添加评论")
    public JsonResult<Void> addNew(CommentDTO commentDTO){
        System.out.println("-------");
        commentService.addNew(commentDTO);
        return JsonResult.ok();
    }
    @PostMapping("/{articleId}/{model}/{page}")
    @ApiOperation("获取更多评论")
    public JsonResult<List<CommentVO>> list(@PathVariable Long articleId,@PathVariable String model,@PathVariable Integer page){
        List<CommentVO> commentVOS=commentService.listByArticleId(articleId,model,page,PAGESIZE);
        return JsonResult.ok(commentVOS);
    }
    @PutMapping("/display/{id}")
    @ApiOperation("显示评论")
    public JsonResult<Void> display(@PathVariable("id") String id){
        commentService.display(id);
        return JsonResult.ok();
    }
    @PutMapping("/hide/{id}")
    @ApiOperation("隐藏评论")
    public JsonResult<Void> hide(@PathVariable("id") String id){
        commentService.hide(id);
        return JsonResult.ok();
    }
}

